//
//  YZMSpreadDetailView.m
//  YZMicroStock
//
//  Created by apple on 17/1/4.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMSpreadDetailView.h"
#import "YZMSpreadInforModel.h"
#import "YZGeneralResultModel.h"
#import "NSNumber+Utils.h"
#import <UIImageView+WebCache.h>
#import "YZClient.h"
#import "YZMShareService.h"
#import "YZMImageActionView.h"

@interface YZMSpreadDetailView (){
    
    UIView *topView;
    UIView *secondView;
    UIView *thirdView;
    UILabel *timesLabel;
    UIView *footerView;
    UIImageView *getInforFromImageView;
    UILabel *alreadyMoneyNumberLabel;
    UILabel *ratioNumberLabel;
    UILabel *ranklabel;
    UILabel *thirdNumberLabel;
    UILabel *thirddetailLabel;
    UIButton *UrlBtn;
    UIView *secondViewNoUser;
    UIButton *loginBtn;
    UIImageView *noUserArrowImageView;
    UIView *thirdViewNoUser;
    UIView *footerViewNoUser;
}

@property(nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic, strong) YZMSpreadInforModel *inforModel;

@end

@implementation YZMSpreadDetailView

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createObject];

    }
    return self;
}


-(void)reloadLoginView{

    if (!YZMUserServiceInstance.currentUser) {
        
        [self createSecondViewNoUser];
        [self createthirtViewNoUser];
        [self createFooterViewNoUser];
        
        //        secondView.hidden = YES;
        //        thirdView.hidden = YES;
        
    }else{
        [self createSecondView];
        
        [self createthirtView];
        [self createFooterView];
        //        secondViewNoUser.hidden = YES;
        //        thirdViewNoUser.hidden = YES;
        [self getuserSpreadInfor];
        [self getWeichatImage];
    }
    
}


#pragma mark createObject
-(void)createObject{
    
    self.scrollView=[UIScrollView new];
    [self addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self).offset(1);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    [self createTopView];
    
    if (!YZMUserServiceInstance.currentUser) {
        
        [self createSecondViewNoUser];
        [self createthirtViewNoUser];
        [self createFooterViewNoUser];
        
    }else{
        [self createSecondView];
        
        [self createthirtView];
        [self createFooterView];
        
        [self getWeichatImage];
    }
    
    [self getuserSpreadInfor];
}


-(void)createTopView{
    
    topView=[UIView new];
    [self.scrollView addSubview:topView];
    topView.backgroundColor=[YZMAppStyle colorForMain];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.equalTo(self.scrollView);
        make.top.equalTo(self.scrollView);
        make.height.mas_equalTo(120);
    }];
    
    UIView *topLine1=[YZMAppStyle splitLine];
    [topView addSubview:topLine1];
    [topLine1 mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(topView).offset(ScreenWidth/3);
        make.top.height.equalTo(topView);
        make.width.mas_equalTo(1);
    }];
    
    UIView *topLine2=[YZMAppStyle splitLine];
    [topView addSubview:topLine2];
    [topLine2 mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(topLine1).offset(ScreenWidth/3);
        make.top.height.equalTo(topView);
        make.width.mas_equalTo(1);
    }];
    
    UIView *topView1=[UIView new];
    [topView addSubview:topView1];
    [topView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(topView);
        make.width.mas_equalTo(ScreenWidth/3-2);
    }];
    
    UIView *topView2=[UIView new];
    [topView addSubview:topView2];
    [topView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(topView);
        make.left.equalTo(topView1.mas_right).offset(1);
        make.width.mas_equalTo(ScreenWidth/3-2);
    }];
    
    UIView *topView3=[UIView new];
    [topView addSubview:topView3];
    [topView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(topView);
        make.left.equalTo(topView2.mas_right).offset(1);
        make.width.mas_equalTo(ScreenWidth/3-2);
    }];
    
    UILabel *firstTitleLabel=[YZMAppStyle labelWithSmallWhite];
    [topView1 addSubview:firstTitleLabel];
    firstTitleLabel.text=@"已赚佣金";
    firstTitleLabel.textAlignment=NSTextAlignmentCenter;
    [firstTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topView1).offset(21);
        make.width.equalTo(topView1);
    }];
    
    alreadyMoneyNumberLabel=[YZMAppStyle labelWithSmallWhite];
    [topView1 addSubview:alreadyMoneyNumberLabel];
    alreadyMoneyNumberLabel.textAlignment=NSTextAlignmentCenter;
    alreadyMoneyNumberLabel.text=@(0.00).p02fString;
    [alreadyMoneyNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(firstTitleLabel.mas_bottom).offset(15);
        make.width.equalTo(topView1);
    }];
    
    UILabel *secondTitleLabel=[YZMAppStyle labelWithSmallWhite];
    [topView2 addSubview:secondTitleLabel];
    secondTitleLabel.text=@"佣金比例";
    secondTitleLabel.textAlignment=NSTextAlignmentCenter;
    [secondTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(firstTitleLabel);
        make.centerX.equalTo(topView2);
    }];
    
    UIButton *secondExplainBtn=[YZMAppStyle explainButton];
    [topView2 addSubview:secondExplainBtn];
    [secondExplainBtn setImage:[UIImage imageNamed:@"icon_markimage"] forState:UIControlStateNormal];
    [secondExplainBtn addTarget:self action:@selector(explainAction) forControlEvents:UIControlEventTouchUpInside];
    [secondExplainBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(secondTitleLabel.mas_right);
        make.top.mas_equalTo(topView2).offset(16);
        make.width.height.mas_equalTo(25);
    }];
    
    ratioNumberLabel=[YZMAppStyle labelWithSmallWhite];
    [topView2 addSubview:ratioNumberLabel];
    ratioNumberLabel.textAlignment=NSTextAlignmentCenter;
    ratioNumberLabel.text=@"0%";
    [ratioNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(alreadyMoneyNumberLabel);
        make.width.equalTo(topView2);
        make.left.equalTo(topLine1);
    }];
    
    UIView *memberView=[UIView new];
    [topView2 addSubview:memberView];
    memberView.layer.masksToBounds=YES;
    memberView.layer.cornerRadius=2.0;
    memberView.backgroundColor=[YZMAppStyle colorForstar];
    [memberView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(topView2);
        make.top.equalTo(ratioNumberLabel.mas_bottom).offset(15);
        make.width.mas_equalTo(93);
        make.height.mas_equalTo(26);
    }];
    
    UIImageView *starImageView=[UIImageView new];
    [memberView addSubview:starImageView];
    [starImageView setImage:[UIImage imageNamed:@"icon_star_bg"]];
    [starImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(memberView);
        make.left.equalTo(memberView).offset(6);
        make.width.height.mas_equalTo(20);
    }];
    
    ranklabel=[YZMAppStyle labelWithSmallGray];
    [memberView addSubview:ranklabel];
    ranklabel.text = @"普通推广员";
    ranklabel.textColor=[YZMAppStyle colorForSpreadText];
    [ranklabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(memberView);
        make.left.equalTo(starImageView.mas_right).offset(3);
    }];
    
    
    UILabel *thirdTitleLabel=[YZMAppStyle labelWithSmallWhite];
    [topView3 addSubview:thirdTitleLabel];
    thirdTitleLabel.text=@"我的用户";
    thirdTitleLabel.textAlignment=NSTextAlignmentCenter;
    [thirdTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(secondTitleLabel);
        make.centerX.equalTo(topView3);
    }];
    
  
    thirdNumberLabel=[YZMAppStyle labelWithSmallWhite];
    [topView3 addSubview:thirdNumberLabel];
    thirdNumberLabel.textAlignment=NSTextAlignmentCenter;
    thirdNumberLabel.text=@"0";
    [thirdNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(ratioNumberLabel);
        make.centerX.equalTo(topView3);
    }];
    
    thirddetailLabel=[YZMAppStyle labelWithSmallWhite];
    [topView3 addSubview:thirddetailLabel];
    thirddetailLabel.textAlignment=NSTextAlignmentCenter;
    thirddetailLabel.text=[NSString stringWithFormat:@"交易%@人",@(0)];
    [thirddetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(memberView);
        make.centerX.equalTo(topView3);
    }];
}

-(void)createSecondView{
    secondView=[UIView new];
    [self.scrollView addSubview:secondView];
    secondView.backgroundColor = [YZMAppStyle colorForMain];
    [secondView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topView.mas_bottom).offset(14);
        make.centerX.equalTo(self.scrollView);
        make.height.mas_equalTo(290);
        make.width.equalTo(self.scrollView);
    }];
    
    timesLabel=[YZMAppStyle labelWithSmallGray];
    [secondView addSubview:timesLabel];
    timesLabel.textAlignment=NSTextAlignmentCenter;
    [timesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondView).offset(19);
        make.centerX.equalTo(self.scrollView);
    }];
    
    NSString *textString=@"复制推广链接发给朋友";
    NSString *string=[textString stringByAppendingString:[NSString stringWithFormat:@" (已访问%@次)",@(0)]];
    NSMutableAttributedString *attString=[[NSMutableAttributedString alloc]initWithString:string];
    [attString addAttribute:NSFontAttributeName value:[YZMAppStyle mediumSizeFont] range:NSMakeRange(0, textString.length)];
    [attString addAttribute:NSForegroundColorAttributeName value:[YZMAppStyle colorForWhite] range:NSMakeRange(0, textString.length)];
    timesLabel.attributedText=attString;
    
    UrlBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [UrlBtn setTitle:@" 复制" forState:UIControlStateNormal];
    [UrlBtn setTitleColor:[YZMAppStyle colorForLightBlueText] forState:UIControlStateNormal];
    [self.scrollView addSubview:UrlBtn];
    [UrlBtn addTarget:self action:@selector(copyUrl) forControlEvents:UIControlEventTouchUpInside];
    UrlBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    UrlBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [UrlBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(timesLabel.mas_bottom).offset(14);
        make.centerX.equalTo(self.scrollView);
    }];
    
    UILabel *intrudeLabel=[YZMAppStyle labelWithMediumWhite];
    [secondView addSubview:intrudeLabel];
    intrudeLabel.textAlignment=NSTextAlignmentCenter;
    intrudeLabel.text=@"推荐朋友扫码，成为你的用户";
    [intrudeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondView).offset(101);
        make.width.equalTo(secondView);
    }];
    
    getInforFromImageView=[UIImageView new];
    [self.scrollView addSubview:getInforFromImageView];
    [getInforFromImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(140);
        make.top.equalTo(intrudeLabel.mas_bottom).offset(14);
        make.centerX.equalTo(secondView);
    }];
    getInforFromImageView.userInteractionEnabled=YES;
    
    UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(imageAction:)];
    [getInforFromImageView addGestureRecognizer:longPress];
    
    UIImageView *arrowImageView=[UIImageView new];
    [secondView addSubview:arrowImageView];
    [arrowImageView setImage:[UIImage imageNamed:@"image_howtogetmoney"]];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.centerX.equalTo(secondView);
    }];
}

-(void)createSecondViewNoUser{
    
        secondViewNoUser=[UIView new];
        [self.scrollView addSubview:secondViewNoUser];
        secondViewNoUser.backgroundColor = [YZMAppStyle colorForMain];
        [secondViewNoUser mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(topView.mas_bottom).offset(14);
            make.centerX.equalTo(self.scrollView);
            make.height.mas_equalTo(104);
            make.width.equalTo(self.scrollView);
        }];
    
        loginBtn = [YZMAppStyle NewsubmitButton];
        [secondViewNoUser addSubview:loginBtn];
        [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(secondViewNoUser).offset(15);
            make.right.equalTo(secondViewNoUser).offset(-15);
            make.top.equalTo(secondViewNoUser).offset(26);
            make.height.mas_offset(44);
        }];
        loginBtn.enabled = YES;
        [loginBtn setTitle:@"登录后获取您的推广链接" forState:UIControlStateNormal];
        [loginBtn setBackgroundColor:[UIColor clearColor]];
        
        [loginBtn setTitleColor:[YZMAppStyle buttonSelectedColor] forState:UIControlStateNormal];
        [loginBtn addTarget:self action:@selector(loginSpread) forControlEvents:UIControlEventTouchUpInside];
    
        noUserArrowImageView = [UIImageView new];
        [secondViewNoUser addSubview:noUserArrowImageView];
        [noUserArrowImageView setImage:[UIImage imageNamed:@"image_howtogetmoney"]];
        [noUserArrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.centerX.equalTo(secondViewNoUser);
        }];
}

-(void)createthirtView{
    
    thirdView=[UIView new];
    [self.scrollView addSubview:thirdView];
    thirdView.backgroundColor=[YZMAppStyle colorForSpreadBg];
        [thirdView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(secondView.mas_bottom);
            make.width.equalTo(secondView);
        }];

    UIView *BGView=[UIView new];
    [thirdView addSubview:BGView];
    [BGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(thirdView);
        make.height.mas_equalTo(15);
    }];
    
#ifdef YZMicroStock_Agent_One
    
    BGView.backgroundColor = [YZMAppStyle colorForBarBGColor];
#endif
    
    UIImageView *detailImageView=[UIImageView new];
    [thirdView addSubview:detailImageView];
    [detailImageView setImage:[UIImage imageNamed:@"icon_particular"]];
    [detailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(BGView);
        make.top.equalTo(BGView.mas_bottom);
    }];
    
    [thirdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(detailImageView);
    }];
}

-(void)createthirtViewNoUser{
    
    thirdViewNoUser=[UIView new];
    [self.scrollView addSubview:thirdViewNoUser];
    thirdViewNoUser.backgroundColor=[YZMAppStyle colorForSpreadBg];
    
    [thirdViewNoUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondViewNoUser.mas_bottom);
        make.width.equalTo(secondViewNoUser);
    }];
    
    
    UIView *BGView=[UIView new];
    [thirdViewNoUser addSubview:BGView];
    [BGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(thirdViewNoUser);
        make.height.mas_equalTo(15);
    }];
#ifdef YZMicroStock_Agent_One
    
    BGView.backgroundColor = [YZMAppStyle colorForBarBGColor];
#endif
    
    UIImageView *detailImageView=[UIImageView new];
    [thirdViewNoUser addSubview:detailImageView];
    [detailImageView setImage:[UIImage imageNamed:@"icon_particular"]];
    [detailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(BGView);
        make.top.equalTo(BGView.mas_bottom);
    }];
    
    [thirdViewNoUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(detailImageView);
    }];
}


-(void)loginSpread{
    
    [YZMUserService showLoginCtrlWithSourcePageName:@"AboutSpread"];
}


-(void)createFooterView{
    
    footerView=[UIView new];
    [self.scrollView addSubview:footerView];
    footerView.backgroundColor=[YZMAppStyle appBackgroundColor];
    
    [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(thirdView.mas_bottom);
        make.width.left.equalTo(thirdView);
        make.height.mas_equalTo(215);
    }];
    
    UIView *lastView=[UIView new];
    [footerView addSubview:lastView];
//    lastView.backgroundColor=[YZMAppStyle appBackgroundColor];
    lastView.backgroundColor=[YZMAppStyle colorForMain];
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.equalTo(footerView);
        make.top.equalTo(footerView).mas_equalTo(14);
        make.height.mas_equalTo(187);
    }];
    
    UILabel *titleLabel=[YZMAppStyle labelWithMediumWhite];
    [lastView addSubview:titleLabel];
    titleLabel.text=@"推广员级别";
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(lastView).offset(13);
    }];
    
    UIView *linefrontView1;
    for (int i=0; i<5; i++) {
        UIView *line=[YZMAppStyle splitLine];
        [lastView addSubview:line];
        [line mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(131);
            make.width.mas_equalTo(1);
            make.top.equalTo(titleLabel.mas_bottom).offset(5);
            if (i==0) {
                make.left.equalTo(lastView).offset(14);
            }else if(i==1){
                make.left.equalTo(linefrontView1.mas_right).offset((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(linefrontView1.mas_right).offset((ScreenWidth-33)/4-10);
            }
        }];
        linefrontView1=line;
    }
    
    UIView *linefrontView2;
    for (int i=0; i<5; i++) {
        UIView *line=[YZMAppStyle splitLine];
        [lastView addSubview:line];
        [line mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(1);
            make.width.mas_equalTo(ScreenWidth-28);
            make.left.equalTo(lastView).offset(14);
            if (i==0) {
                make.top.equalTo(titleLabel.mas_bottom).offset(5);
            }else if(i==1){
                make.top.equalTo(linefrontView2.mas_bottom).offset(43);
            }else{
                make.top.equalTo(linefrontView2.mas_bottom).offset(28);
            }
        }];
        linefrontView2=line;
    }
    
    UILabel *firstLineLabel=[YZMAppStyle labelWithSmallGray];
    [lastView addSubview:firstLineLabel];
    firstLineLabel.textAlignment=NSTextAlignmentCenter;
    firstLineLabel.text=@"级别";
    [firstLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(linefrontView2.mas_bottom).offset(-98);
        make.left.equalTo(lastView).offset(15);
        make.width.mas_equalTo((ScreenWidth-33)/4+30);
    }];
    
    
    NSArray *firsttitleArray1=@[@"下线交易",@"交易提成",@"下线"];
    UILabel *titleFrontLabel;
    for (int i=0; i<3; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallGray];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text=firsttitleArray1[i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(firstLineLabel).offset(-8);
            make.width.mas_equalTo((ScreenWidth-33)/4-10);
            if (i==0) {
                make.left.equalTo(firstLineLabel.mas_right).offset(1);
            }else{
                make.left.equalTo(titleFrontLabel.mas_right).offset(1);
            }
        }];
        titleFrontLabel=titleLabel;
    }
    
    NSArray *firsttitleArray2=@[@"用户数量",@"佣金比例",@"有效期"];
    UILabel *titleFrontLabe2;
    for (int i=0; i<3; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallGray];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text=firsttitleArray2[i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleFrontLabel.mas_bottom);
            make.width.mas_equalTo((ScreenWidth-33)/4-10);
            if (i==0) {
                make.left.equalTo(firstLineLabel.mas_right).offset(1);
            }else{
                make.left.equalTo(titleFrontLabe2.mas_right).offset(1);
            }
        }];
        titleFrontLabe2=titleLabel;
    }
    
//    NSArray *normalArray=@[[self normalString:0],[self normalString:1],[self normalString:2],[self normalString:3]];
    UILabel *normalFrontLabe;
    for (int i=0; i<4; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallWhite];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text= [self normalString:i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView).offset(90);
            if (i==0) {
                make.left.equalTo(lastView).offset(15);
                make.width.mas_equalTo((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(normalFrontLabe.mas_right).offset(1);
                make.width.mas_equalTo((ScreenWidth-33)/4-10);
            }
        }];
        normalFrontLabe=titleLabel;
    }
    
//    NSArray *goldArray=@[[self goldString:0],[self goldString:1],[self goldString:2],[self goldString:3]];
    UILabel *goldFrontLabe;
    for (int i=0; i<4; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallWhite];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text = [self goldString:i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView).offset(117);
            if (i==0) {
                make.left.equalTo(lastView).offset(15);
                make.width.mas_equalTo((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(goldFrontLabe.mas_right).offset(1);
                make.width.mas_equalTo((ScreenWidth-33)/4-10);
            }
        }];
        goldFrontLabe=titleLabel;
    }
    
//    NSArray *superArray=@[[self superString:0],[self superString:1],[self superString:2],[self superString:3]];
    UILabel *superFrontLabe;
    for (int i=0; i<4; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallWhite];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text= [self superString:i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView).offset(144);
            if (i==0) {
                make.left.equalTo(lastView).offset(15);
                make.width.mas_equalTo((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(superFrontLabe.mas_right).offset(1);
                make.width.mas_equalTo((ScreenWidth-33)/4-10);
            }
        }];
        superFrontLabe=titleLabel;
    }
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(footerView.mas_bottom);
    }];
}

-(void)createFooterViewNoUser{
    
    footerViewNoUser=[UIView new];
    [self.scrollView addSubview:footerViewNoUser];
    footerViewNoUser.backgroundColor=[YZMAppStyle appBackgroundColor];
    
    [footerViewNoUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(thirdViewNoUser.mas_bottom);
        make.width.left.equalTo(thirdViewNoUser);
        make.height.mas_equalTo(215);
    }];
    
    UIView *lastView=[UIView new];
    [footerViewNoUser addSubview:lastView];
    //    lastView.backgroundColor=[YZMAppStyle appBackgroundColor];
    lastView.backgroundColor=[YZMAppStyle colorForMain];
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.equalTo(footerViewNoUser);
        make.top.equalTo(footerViewNoUser).mas_equalTo(14);
        make.height.mas_equalTo(187);
    }];
    
    UILabel *titleLabel=[YZMAppStyle labelWithMediumWhite];
    [lastView addSubview:titleLabel];
    titleLabel.text=@"推广员级别";
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(lastView).offset(13);
    }];
    
    UIView *linefrontView1;
    for (int i=0; i<5; i++) {
        UIView *line=[YZMAppStyle splitLine];
        [lastView addSubview:line];
        [line mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(131);
            make.width.mas_equalTo(1);
            make.top.equalTo(titleLabel.mas_bottom).offset(5);
            if (i==0) {
                make.left.equalTo(lastView).offset(14);
            }else if(i==1){
                make.left.equalTo(linefrontView1.mas_right).offset((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(linefrontView1.mas_right).offset((ScreenWidth-33)/4-10);
            }
        }];
        linefrontView1=line;
    }
    
    UIView *linefrontView2;
    for (int i=0; i<5; i++) {
        UIView *line=[YZMAppStyle splitLine];
        [lastView addSubview:line];
        [line mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(1);
            make.width.mas_equalTo(ScreenWidth-28);
            make.left.equalTo(lastView).offset(14);
            if (i==0) {
                make.top.equalTo(titleLabel.mas_bottom).offset(5);
            }else if(i==1){
                make.top.equalTo(linefrontView2.mas_bottom).offset(43);
            }else{
                make.top.equalTo(linefrontView2.mas_bottom).offset(28);
            }
        }];
        linefrontView2=line;
    }
    
    UILabel *firstLineLabel=[YZMAppStyle labelWithSmallGray];
    [lastView addSubview:firstLineLabel];
    firstLineLabel.textAlignment=NSTextAlignmentCenter;
    firstLineLabel.text=@"级别";
    [firstLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(linefrontView2.mas_bottom).offset(-98);
        make.left.equalTo(lastView).offset(15);
        make.width.mas_equalTo((ScreenWidth-33)/4+30);
    }];
    
    
    NSArray *firsttitleArray1=@[@"下线交易",@"交易提成",@"下线"];
    UILabel *titleFrontLabel;
    for (int i=0; i<3; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallGray];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text=firsttitleArray1[i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(firstLineLabel).offset(-8);
            make.width.mas_equalTo((ScreenWidth-33)/4-10);
            if (i==0) {
                make.left.equalTo(firstLineLabel.mas_right).offset(1);
            }else{
                make.left.equalTo(titleFrontLabel.mas_right).offset(1);
            }
        }];
        titleFrontLabel=titleLabel;
    }
    
    NSArray *firsttitleArray2=@[@"用户数量",@"佣金比例",@"有效期"];
    UILabel *titleFrontLabe2;
    for (int i=0; i<3; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallGray];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text=firsttitleArray2[i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleFrontLabel.mas_bottom);
            make.width.mas_equalTo((ScreenWidth-33)/4-10);
            if (i==0) {
                make.left.equalTo(firstLineLabel.mas_right).offset(1);
            }else{
                make.left.equalTo(titleFrontLabe2.mas_right).offset(1);
            }
        }];
        titleFrontLabe2=titleLabel;
    }
    
    //    NSArray *normalArray=@[[self normalString:0],[self normalString:1],[self normalString:2],[self normalString:3]];
    UILabel *normalFrontLabe;
    for (int i=0; i<4; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallWhite];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text= [self normalString:i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView).offset(90);
            if (i==0) {
                make.left.equalTo(lastView).offset(15);
                make.width.mas_equalTo((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(normalFrontLabe.mas_right).offset(1);
                make.width.mas_equalTo((ScreenWidth-33)/4-10);
            }
        }];
        normalFrontLabe=titleLabel;
    }
    
    //    NSArray *goldArray=@[[self goldString:0],[self goldString:1],[self goldString:2],[self goldString:3]];
    UILabel *goldFrontLabe;
    for (int i=0; i<4; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallWhite];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text = [self goldString:i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView).offset(117);
            if (i==0) {
                make.left.equalTo(lastView).offset(15);
                make.width.mas_equalTo((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(goldFrontLabe.mas_right).offset(1);
                make.width.mas_equalTo((ScreenWidth-33)/4-10);
            }
        }];
        goldFrontLabe=titleLabel;
    }
    
    //    NSArray *superArray=@[[self superString:0],[self superString:1],[self superString:2],[self superString:3]];
    UILabel *superFrontLabe;
    for (int i=0; i<4; i++) {
        UILabel *titleLabel=[YZMAppStyle labelWithSmallWhite];
        [lastView addSubview:titleLabel];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.text= [self superString:i];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView).offset(144);
            if (i==0) {
                make.left.equalTo(lastView).offset(15);
                make.width.mas_equalTo((ScreenWidth-33)/4+30);
            }else{
                make.left.equalTo(superFrontLabe.mas_right).offset(1);
                make.width.mas_equalTo((ScreenWidth-33)/4-10);
            }
        }];
        superFrontLabe=titleLabel;
    }
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(footerViewNoUser.mas_bottom);
    }];
}

-(NSString *)normalString:(int )index{
    NSArray *Arr=@[@"普通推广员",@"<=9人",@"0.01%",@"半年"];
    return Arr[index];
}

-(NSString *)goldString:(int )index{
    NSArray *Arr=@[@"金牌推广员",@"10-49人",@"0.03%",@"一年"];
    return Arr[index];
}

-(NSString *)superString:(int )index{
    NSArray *Arr=@[@"钻石推广员",@">=50人",@"0.05%",@"两年"];
    return Arr[index];
}


-(void)explainAction{
    
    [self.scrollView setContentOffset:CGPointMake(0,self.scrollView.contentSize.height -self.scrollView.bounds.size.height) animated:YES];
}

-(void)copyUrl{
    if (_inforModel.generalizeUrl) {
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        pasteboard.string = _inforModel.generalizeUrl;
        [MBProgressHUD showMessage:@"复制成功！"];
    }else{
        
        [MBProgressHUD showMessage:@"复制失败，请重试！"];
    }

    
}

-(void)getuserSpreadInfor{
    /*无网处理*/
    if (kNetworkNotReachability) {

        [NSError yz_showMessageForNoWifi];
        return;
    }
    
    [YZClient getinforAboutUserSpreadsuccess:^(NSURLSessionDataTask *task, id responseObject) {
        YZGeneralResultModel *topModel=responseObject;
        if (topModel.success) {
            _inforModel=topModel.data;
            alreadyMoneyNumberLabel.text=@(_inforModel.commission).p02fString;
            ratioNumberLabel.text=[[NSString stringWithFormat:@"%@",@(_inforModel.ratio)] stringByAppendingString:@"%"];
            ranklabel.text=_inforModel.commType;
            thirdNumberLabel.text=[NSString stringWithFormat:@"%@",@(_inforModel.userCount)];
            thirddetailLabel.text=[NSString stringWithFormat:@"交易%@人",@(_inforModel.tradeCount)];
            NSString *textString=@"复制推广链接发给朋友";
            NSString *string=[textString stringByAppendingString:[NSString stringWithFormat:@" (已访问%@次)",@(_inforModel.generalizeVisitCount)]];
            NSMutableAttributedString *attString=[[NSMutableAttributedString alloc]initWithString:string];
            [attString addAttribute:NSFontAttributeName value:[YZMAppStyle mediumSizeFont] range:NSMakeRange(0, textString.length)];
            [attString addAttribute:NSForegroundColorAttributeName value:[YZMAppStyle colorForMainTextColor] range:NSMakeRange(0, textString.length)];
            timesLabel.attributedText=attString;
            [UrlBtn setTitle:[_inforModel.generalizeUrl stringByAppendingString:@" 复制"] forState:UIControlStateNormal];
            
        }else{
            [topModel showMessage];
        }
    } failure:^(NSError *error) {
        [error yz_showMessage];
    }];
}

-(void)getWeichatImage{
    
    NSString *urlStr = [NSString stringWithFormat:@"%@/%@?device=3", URL_BASE_STRING, URL_FOR_GET_WEICHAT_IMAGE];
    NSURL *url = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [getInforFromImageView sd_setImageWithURL:url placeholderImage:nil options:SDWebImageHandleCookies | SDWebImageCacheMemoryOnly];
}

-(void)imageAction:(UILongPressGestureRecognizer *)sender{
    
    if ([sender state]==UIGestureRecognizerStateBegan) {
        YZMImageActionView *imageActionView=[YZMImageActionView new];
        NSMutableArray *array=[NSMutableArray arrayWithObjects:@"分享给朋友",@"保存到相册",@"取消", nil];
        
        if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]]) {
            array=[NSMutableArray arrayWithObjects:@"保存到相册",@"取消", nil];
        }
        
        imageActionView.datasource=[NSMutableArray arrayWithArray:array];
        
        imageActionView.shareBlock=^(){
            [[YZMShareService sharedService]shareTextToPlatformType:UMSocialPlatformType_WechatSession withContent:@{@"image":getInforFromImageView.image}];
        };
        imageActionView.saveBlock=^(){
            [self saveImageToPhotos:getInforFromImageView.image];
        };
        [imageActionView show];
    }
}

- (void)saveImageToPhotos:(UIImage*)savedImage
{
    UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
    
}

- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
    NSString *msg = nil ;
    
    if(error != NULL){
        
        msg = @"保存图片失败" ;
    }else{
        
        msg = @"保存图片成功" ;
    }
    
    [MBProgressHUD showMessage:msg];
}

@end
